package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.JobOption;
import com.itheima.pojo.StudentOption;
import com.itheima.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public JobOption empJobData() {
        List<Map> mapList = empMapper.getJobData();
        log.info("mapList : {}",mapList);
        List<Object> jobList = mapList.stream().map(map -> {
            return map.get("pos");
        }).collect(Collectors.toList());
        List<Object> dataList = mapList.stream().map(map -> {
            return map.get("posCount");
        }).collect(Collectors.toList());
        return new JobOption(jobList,dataList);

    }

    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    @Override
    public ClazzOption getStudentCountData() {
        List<Map> mapList = studentMapper.getStudentCountData();
        List<Object> clazzList = mapList.stream().map(dataMap -> dataMap.get("clazzname")).toList();
        List<Object> dataList = mapList.stream().map(dataMap -> dataMap.get("clazzCount")).toList();
        return new ClazzOption(clazzList, dataList);
    }

    @Override
    public List<Map> getStudentDegreeData() {

        return studentMapper.countStudentDegreeData();
    }




}
